package o2o.business.jms;

import com.jinyou.utils.common.ValidateUtil;
import com.jinyouapp.common.tools.jms.model.JMSNotify;
import com.jinyouapp.common.utils.system.ConfigUtils;
import notice.cache.UserOnlyInfoMemory;
import o2o.cache.agent.*;
import o2o.cache.area.RegionInfoMemory;
import o2o.cache.company.SysCityCompanyMemory;
import o2o.cache.company.SysCityCompanyUserRelationMemory;
import o2o.cache.company.postman.*;
import o2o.cache.divide.CityAgentFeeMemory;
import o2o.cache.divide.DividingInfoMemory;
import o2o.cache.order.OrderPayMemory;
import o2o.cache.postman.CityPostmanMemory;
import o2o.cache.shop.*;
import o2o.cache.user.UserInfoMemory;
import o2o.cache.user.UserPwdMemory;
import o2o.cache.wallet.UserWalletFlowMemory;
import o2o.config.jms.config.JMSTypeContent;
import o2o.service.company.postman.ShopSignCompanyService;
import o2o.utils.CommonUtils;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.Set;

/**
 * 处理通过mq接受到的数据
 * 类名称：MQDataBusiness
 * 类描述：
 * 创建人：Jahnke 1029777564@qq.com
 * 创建时间：2016年8月29日 下午2:54:36
 * 修改备注：
 */
public class MQDataBusiness {

    public static String proFlagS = "";
    public static String proNameS = "";
    private static Logger logger = Logger.getLogger(MQDataBusiness.class);

    static {
        InputStream in = ConfigUtils.class.getClassLoader().getResourceAsStream("config.properties");
        Properties prop = new Properties();
        try {
            prop.load(in);
        } catch (IOException var3) {
            logger.error("ERROR---Failed to load config.properties file: " + var3.getMessage(), var3);
        }
        proFlagS = prop.getProperty("pro.flag").trim();
        proNameS = prop.getProperty("pro.projectName").trim();
    }

    public static void dealData(JMSNotify notify) {
        System.out.println(notify);
        if ((true) & ((notify.getIsSync() == 1) || !notify.getProflag().equals(proFlagS))) {
            switch (notify.getType()) {
                case JMSTypeContent.APP_VERSION_MODIFY: {
                    //  SysVersionMemory.getInstance().update(notify.getInt01());             // 更新版本
                }
                break;
                case JMSTypeContent.USER_ADD: {               // 新增用户
                    UserInfoMemory.getInstance().addUserInfo(notify.getStr01());        // 添加新用户
                    UserPwdMemory.getInstance().getPassword(notify.getStr01());         // 添加新用户的密码缓存信息
                }
                break;
                case JMSTypeContent.USER_PASSWORD_MODIFY: {    // 修改密码(通过验证码找回密码)
                    UserPwdMemory.getInstance().modifyPassword(notify.getStr01(), notify.getStr02());
                }
                break;
                case JMSTypeContent.USER_PAY_PASSWORD_MODIFY: { // 修改支付密码
                    UserPwdMemory.getInstance().modifyPayPassword(notify.getStr01(), notify.getStr02());
                }
                break;
                case JMSTypeContent.USER_TYPE_MODIFY: {        // 修改用户类型
                    UserInfoMemory.getInstance().modifyUserType(notify.getStr01(), notify.getInt01());
                }
                break;
                case JMSTypeContent.USER_INFO_MODIFY: {        // 修改用户信息
                    UserInfoMemory.getInstance().modifyUserInfo(notify.getStr01());
                }
                break;
                case JMSTypeContent.USER_INFO_DEL: {
                    UserInfoMemory.getInstance().del(notify.getStr01());
                }
                break;
                case JMSTypeContent.USER_INFO_LOCK: {
                    UserInfoMemory.getInstance().lock(notify.getStr01());
                }
                break;
                case JMSTypeContent.USERS_CURR_NOTICE: {       // 多人同步
                    Set<String> users = notify.getReceivers();
                    if ((users != null) && (users.size() > 0)) {
                        for (String username : users) {
                            UserOnlyInfoMemory.getInstance().upLastNewNoticeTime(username, notify.getCreateTim());
                        }
                    }
                }
                break;
                case JMSTypeContent.SHOP_INFO_ADD:                                   // 添加店铺
                    ShopMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.SHOP_INFO_UPDATE:
                    ShopMemory.getInstance().modifyById(notify.getLong01());    // 修改店铺信息
                    break;
                case JMSTypeContent.SHOP_INFOS_UPDATE:
                    ShopMemory.getInstance().modify(notify.getStr01());         // 修改店铺信息
                    break;
                case JMSTypeContent.SHOP_INFOS_UPDATE_BY_CITY:
                    ShopMemory.getInstance().modifyV2(notify.getStr01());       // 修改店铺信息，根据城市
                    break;
                case JMSTypeContent.SHOP_INFO_DELETE:
                    ShopMemory.getInstance().delete(notify.getLong01());        // 删除店铺信息
                    break;
                case JMSTypeContent.SHOP_SPECIAL_RELOAD:
                    SpecialShopListMemory.getInstance().reload();
                    break;
                case JMSTypeContent.SHOP_TYPE_RELATION_RELOAD:
                    ShopTypeRelationMemory.getInstance().delete(notify.getLong01());    // 店铺关联关系-删除后新增
                    ShopTypeRelationMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.SHOP_TYPE_RELATION_ADD:
                    ShopTypeRelationMemory.getInstance().add(notify.getLong01());       // 店铺关联关系-添加
                    break;
                case JMSTypeContent.SHOP_TYPE_RELATION_DEL:
                    ShopTypeRelationMemory.getInstance().delete(notify.getLong01());    // 店铺关联关系-删除
                    break;

                case JMSTypeContent.AGENT_CITY_ADD:
                    CityAgentMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.AGENT_CITY_RELOAD:
                    CityAgentMemory.getInstance().run();
                    break;
                case JMSTypeContent.AGENT_CITY_UPDATE:
                    CityAgentMemory.getInstance().modify(notify.getLong01());
                    break;
                case JMSTypeContent.SHOP_TIP_RELOAD:
                    ShopTipMemory.getInstance().load();
                    break;
                case JMSTypeContent.SHOP_TIP_ADD:
                    ShopTipMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.SHOP_TIP_UPDATE:
                    ShopTipMemory.getInstance().modify(notify.getLong01());
                    break;
                case JMSTypeContent.SHOP_TIP_DELETE:
                    ShopTipMemory.getInstance().delete(notify.getStr01());
                    break;
                case JMSTypeContent.SHOP_TIP_RELATION_RELOAD:
                    ShopTipRelationMemory.getInstance().load();
                    break;
                case JMSTypeContent.SHOP_TIP_AND_RELATION_RELOAD:
                    ShopTipMemory.getInstance().load();
                    ShopTipRelationMemory.getInstance().load();
                    break;
                case JMSTypeContent.AGENT_MANAGER_ADD:                               //  区域主管信息--新增
                    AgentManagerMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.AGENT_MANAGER_MODIFY:                           //  区域主管信息--修改
                    AgentManagerMemory.getInstance().modify(notify.getStr01());
                    break;
                case JMSTypeContent.AGENT_MANAGER_DEL:                              //  区域主管信息--删除
                    AgentManagerMemory.getInstance().del(notify.getStr01());
                    break;
                case JMSTypeContent.AGENT_POSTMAN_RELATION_ADD:                              // 代理和配送员关系
                    PostmanAgentRelationMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.AGENT_POSTMAN_RELATION_ADD_BY_TIME:
                    PostmanAgentRelationMemory.getInstance().addByCreateTime(notify.getLong01());
                    break;
                case JMSTypeContent.AGENT_POSTMAN_RELATION_DELETE:
                    PostmanAgentRelationMemory.getInstance().delete(notify.getLong01(), notify.getStr01());
                    break;
                case JMSTypeContent.AGENT_POSTMAN_RELATION_RELOAD_BY_AGENT:
                    PostmanAgentRelationMemory.getInstance().reloadByAgentId(notify.getLong01());
                    break;
                case JMSTypeContent.SHOP_AGENT_RELATION_RELOAD:
                    ShopAgentRelationMemory.getInstance().run();
                    break;
                case JMSTypeContent.SHOP_AGENT_RELATION_ADD:
                    ShopAgentRelationMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.SHOP_AGENT_RELATION_DELETE:
                    ShopAgentRelationMemory.getInstance().delete(notify.getLong01(), notify.getLong02());
                    break;
                case JMSTypeContent.USER_AGENT_RELATION_ADD:
                    UserAgentRelationMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.USER_AGENT_RELATION_DELETE_BY_USER:
                    UserAgentRelationMemory.getInstance().deleteByUsername(notify.getStr01());
                    break;
                case JMSTypeContent.USER_AGENT_RELATION_DELETE_BY_AGENT:
                    UserAgentRelationMemory.getInstance().deleteUserAgent(notify.getStr01(), notify.getLong01());
                    break;
                case JMSTypeContent.REGION_INFO_ADD:
                    RegionInfoMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.REGION_INFO_RELOAD_BY_CITY:
                    RegionInfoMemory.getInstance().reloadRegionOfCity(notify.getStr01());
                    break;
                case JMSTypeContent.COMPANY_POST_INFO_ADD:
                    PostCompanyMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.COMPANY_POST_INFO_UPDATE:
                    PostCompanyMemory.getInstance().modify(notify.getLong01());
                    break;
                case JMSTypeContent.COMPANY_POST_INFO_DELETE:
                    PostCompanyMemory.getInstance().del(notify.getLong01());
                    break;
                case JMSTypeContent.COMPANY_POST_DELIVERY_TYPE_INFO_RELOAD:
                    CompanyTypeRelationMemory.getInstance().reload(notify.getLong01());
                    break;
                case JMSTypeContent.COMPANY_POSTMAN_SIGN_ADD:
                    PostmanSignCompanyMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.COMPANY_POSTMAN_SIGN_UPDATE:
                    PostmanSignCompanyMemory.getInstance().modify(notify.getLong01());
                    break;
                case JMSTypeContent.COMPANY_POSTMAN_SIGN_DELETE:
                    PostmanSignCompanyMemory.getInstance().del(notify.getLong01());
                    break;
                case JMSTypeContent.POSTMAN_DELIVERY_TYPE_RELOAD:
                    PostmanTypeRelationMemory.getInstance().load(notify.getStr01());
                    break;
                case JMSTypeContent.POST_TYPE_INFO_ADD:
                    PostTypeMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.POST_TYPE_INFO_UPDATE:
                    PostTypeMemory.getInstance().modify(notify.getLong01());
                    break;
                case JMSTypeContent.POST_TYPE_INFO_DELETE:
                    PostTypeMemory.getInstance().delete(notify.getLong01());
                    break;
                case JMSTypeContent.SYS_CITY_COMPANY_ADD:
                    SysCityCompanyMemory.getInstance().add(notify.getLong01());
                    SysCityCompanyUserRelationMemory.getInstance().add(notify.getLong02());
                    break;
                case JMSTypeContent.SYS_CITY_COMPANY_USER_ADD:
                    SysCityCompanyUserRelationMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.SYS_CITY_COMPANY_USER_UPDATE:
                    SysCityCompanyUserRelationMemory.getInstance().modify(notify.getStr01());
                    break;
                case JMSTypeContent.SYS_CITY_COMPANY_USER_DELETE:
                    SysCityCompanyUserRelationMemory.getInstance().del(notify.getStr01());
                    break;
                case JMSTypeContent.CITY_AGENT_FEE_INFO_ADD:
                    CityAgentFeeMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.CITY_AGENT_FEE_INFO_UPDATE:
                    CityAgentFeeMemory.getInstance().modify(notify.getLong01());
                    break;
                case JMSTypeContent.CITY_AGENT_FEE_INFO_DELETE:
                    CityAgentFeeMemory.getInstance().del(notify.getLong01());
                    break;
                case JMSTypeContent.DIVIDING_INFO_ADD:
                    DividingInfoMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.DIVIDING_INFO_UPDATE:
                    DividingInfoMemory.getInstance().modify(notify.getLong01());
                    break;



                case JMSTypeContent.POSTMAN_INFO_ADD:
                    CityPostmanMemory.getInstance().add(notify.getLong01());
                    break;
                case JMSTypeContent.POSTMAN_INFO_MODIFY:
                    CityPostmanMemory.getInstance().modifyByUsername(notify.getStr01());
                    break;
                case JMSTypeContent.POSTMAN_RELOAD_BY_CITY:
                    CityPostmanMemory.getInstance().reloadCity(notify.getStr01());
                    break;
                case JMSTypeContent.POSTMAN_WORK_SET:
                    CityPostmanMemory.getInstance().setIsWork(notify.getStr01(), notify.getInt01());
                    break;
                case JMSTypeContent.POSTMAN_LOCK_SET:
                    CityPostmanMemory.getInstance().setIsLock(notify.getStr01(), notify.getInt01());
                    break;
                case JMSTypeContent.POSTMAN_REMIND_SET:
                    CityPostmanMemory.getInstance().setRemind(notify.getStr01(), notify.getInt01(), notify.getInt02());
                    break;
                case JMSTypeContent.ORDER_PAY_RELOAD:
                    OrderPayMemory.getInstance().run();
                    break;
                case JMSTypeContent.ORDER_PAY_ADD:
                    OrderPayMemory.getInstance().add(notify.getStr01());
                    break;
                case JMSTypeContent.ORDER_PAY_MODIFY:
                    OrderPayMemory.getInstance().modify(notify.getStr01());
                    break;
                case JMSTypeContent.SHOP_SIGN_COMPANY_CLEAN:
                    ShopSignCompanyService.getInstance().clearCache(notify.getLong01(), notify.getLong02());
                    break;
                case JMSTypeContent.SHOP_SIGN_COMPANY_MODIFY:
                    ShopSignCompanyService.getInstance().updateCacheOfShopSign(notify.getLong01());
                    break;
                case JMSTypeContent.USER_WALLET_FLOW_ADD:
                    UserWalletFlowMemory.getInstance().addFLow(notify.getStr01());
                    break;

                default:
                    break;
            }
        }
    }
}
